﻿using Modern.MvvM;
using System;

namespace KouDai.Core.Service.Navigation
{
    public class NavigateCommand : RelayCommand
    {
        private readonly INavigateService _navigateService;

        public NavigateCommand(Action execute, INavigateService navigateService)
            : base(execute)
        {
            _navigateService = navigateService;
            _navigateService.CanGoBackChanged += EventService.MakeWeakSimple(OnCanGoBackChanged, h => _navigateService.CanGoBackChanged -= h);
        }

        public void OnCanGoBackChanged(object sender, EventArgs e)
        {
            RaiseCanExecuteChanged();
        }

        public override bool CanExecute(object parameter)
        {
            return _navigateService.CanGoBack;
        }
    }
}
